package com.edushare.common.vo;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.edushare.common.constants.ApplicationConstants;

public class FileFolderObject implements Comparable<FileDirectories> {

	public static final int FOLDER_TYPE 	= 1;
	public static final int FILE_TYPE 		= 2;
	
	private String title;
	private Date dateCreation;
	private Date dateUpdated;
	private String url;
	private int type;
	private int id;
	private String visibility; //the two lettered code from file directories
	private Integer creatorId;
	
	public int compareTo(FileDirectories fd) {
		
		return 0;
	}
	

	public FileFolderObject(FilesUploaded fu){
		if(fu == null)
			return;
		
		this.title = fu.getFileOrigName();
		this.dateCreation = fu.getUploadTimestamp();
		this.dateUpdated = fu.getUploadTimestamp();
		this.url = fu.getFileDownloadUrl();
		this.type = FILE_TYPE;
		this.id = fu.getFileUploadedId();
		this.visibility = fu.getFileDirectory().getReadPerm();
		if(fu.getUploader()!=null)
			this.creatorId = fu.getUploader().getUserId();
	}
	
	public FileFolderObject(FileDirectories fd){
		
		if(fd==null)
			return;
		
		//TODO: need to set URL
		this.title = fd.getDirectoryName();
		this.dateCreation = fd.getCreationTimestamp();
		this.dateUpdated = fd.getUpdateTimestamp();
		this.type = FOLDER_TYPE;
		this.id = fd.getFileDirectoryId();
		this.visibility = fd.getReadPerm();
		if(fd.getCreator()!=null)
			this.creatorId = fd.getCreator().getUserId();
	}

	public Date getDateCreation() {
		return dateCreation;
	}

	public void setDateCreation(Date dateCreation) {
		this.dateCreation = dateCreation;
	}

	public Date getDateUpdated() {
		return dateUpdated;
	}

	public String getDateUpdatedStr() {
		if(dateUpdated==null)
			return "Not Available";
		return new SimpleDateFormat(ApplicationConstants.TIMESTAMP_FORMAT).format(dateUpdated);
	}
	
	public void setDateUpdated(Date dateUpdated) {
		this.dateUpdated = dateUpdated;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public void setTitle(String title) {
		this.title = title;
	}


	public String getTitle() {
		return title;
	}


	public void setId(int id) {
		this.id = id;
	}


	public int getId() {
		return id;
	}


	public void setVisibility(String visibility) {
		this.visibility = visibility;
	}


	public String getVisibility() {
		return visibility;
	}


	public void setCreatorId(Integer creatorId) {
		this.creatorId = creatorId;
	}


	public Integer getCreatorId() {
		return creatorId;
	}

}
